//
//  ZM_ImgL_TVCell.m
//  YYFMMall
//
//  Created by chenzm on 2019/9/10.
//  Copyright © 2019 YuYou1. All rights reserved.
//

#import "ZM_ImgL_TVCell.h"

@interface ZM_ImgL_TVCell()

@end

@implementation ZM_ImgL_TVCell


#pragma mark - Methods
-(void)setLeftImg_mar:(CGFloat)leftImg_mar{
    _leftImg_mar = leftImg_mar;
}

-(void)setImg_fixSize:(CGSize)img_fixSize{
    _img_fixSize = img_fixSize;
    [self.imgV mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(img_fixSize);
        make.centerY.mas_equalTo(self);
        make.left.mas_equalTo(15);
    }];
}

-(void)setImg_corner:(CGFloat)img_corner{
    _img_corner = img_corner;
    [ZMSpeedy zm_changeControl:self.imgV cornerRadius:img_corner borderWidth:0 borderColor:nil mask:YES];
}


-(void)setCellByImgStr:(NSString *)imgStr lblStr:(NSString *)lblStr{
    UIImage *img = nil;
    if ([imgStr containsString:@"http"]) {
        img = kImgURL(imgStr);
    }else{
        img = kImage(imgStr);
    }
    if (img) {
        _imgV.image = img;
        [_imgV mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(self.img_fixSize.height > 0?self.img_fixSize:img.size);
            make.centerY.mas_equalTo(self);
            make.left.mas_equalTo(15);
        }];

        [_lbl mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self);
            make.left.mas_equalTo(self.imgV.mas_right).offset(10);
            make.right.mas_equalTo(self).offset(-15);
        }];
    }else{
        [_lbl mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self);
            if (self.leftImg_mar > 0) {
                make.left.mas_equalTo(self.leftImg_mar);
            }else{
                make.left.mas_equalTo(15);
            }
        }];
    }
    _lbl.text = kIsEmptyStr(lblStr)?@"":lblStr;
}

#pragma mark - Intial
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUpBaseData];
        [self setUpUI];
    }
    return self;
}

///基本数据设置
-(void)setUpBaseData{
    
}
///添加控件
-(void)setUpUI{
    [self imgV];
    [self lbl];
    [self lineV];
}

#pragma mark - lazyLoad
-(UIImageView *)imgV{
    if (!_imgV) {
        _imgV = [UIImageView new];
        _imgV.contentMode = UIViewContentModeScaleToFill;
        [self addSubview:_imgV];
        [_imgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.right.mas_equalTo(-15);
            make.top.mas_equalTo(3);
            make.bottom.mas_equalTo(-3);
        }];
    }
    return _imgV;
}

-(UILabel *)lbl{
    if (!_lbl) {
        _lbl = [UILabel new];
        _lbl.font = kMediumFont(15);
        _lbl.textColor = kBlackColor;
        _lbl.textAlignment = NSTextAlignmentLeft;
        [self addSubview:_lbl];
        [_lbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self);
            make.left.mas_equalTo(self.imgV.mas_right).offset(10);
            make.right.mas_equalTo(self).offset(-15);
        }];
    }
    return _lbl;
}


-(UIView *)lineV{
    if (!_lineV) {
        _lineV = [UIView new];
        _lineV.backgroundColor = kHexColor(0xEEEEEE);
        [self addSubview:_lineV];
        [_lineV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self);
            make.left.mas_equalTo(15);
            make.right.mas_equalTo(-15);
            make.height.mas_equalTo(1);
        }];
    }
    return _lineV;
}


@end

